<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>管理后台</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
    <h1>管理员后台</h1>

    <h2>添加分类</h2>
    <form method="post">
        <input type="hidden" name="action" value="add_category">
        <input type="text" name="category_name" placeholder="分类名称" required>
        <button type="submit">添加分类</button>
    </form>

    <h2>添加网址</h2>
    <form method="post">
        <input type="hidden" name="action" value="add_website">
        <select name="category_id" required>
            {% for category in categories %}
                <option value="{{ category.id }}">{{ category.name }}</option>
            {% endfor %}
        </select>
        <input type="url" name="website_url" placeholder="https://example.com" required>
        <button type="submit">添加网址</button>
    </form>


    <h2>现有网址</h2>
    <ul>
        {% for website in websites %}
            <li>
                <strong>{{ website.title or website.url }}</strong>
                <p>{{ website.description }}</p>
                <small>所属分类: {{ website.category.name }}</small>
                <form style="display:inline;" method="post">
                    <input type="hidden" name="action" value="delete_website">
                    <input type="hidden" name="website_id" value="{{ website.id }}">
                    <button type="submit">删除网址</button>
                </form>
            </li>
        {% endfor %}
    </ul>

    <h2>现有分类</h2>
    <ul>
        {% for category in categories %}
            <li>
                {{ category.name }}
                <form style="display:inline;" method="post">
                    <input type="hidden" name="action" value="delete_category">
                    <input type="hidden" name="category_id" value="{{ category.id }}">
                    <button type="submit">删除分类</button>
                </form>
            </li>
        {% endfor %}
    </ul>
</body>
</html>